const { resolve } = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const { DefinePlugin } = require('webpack');
module.exports = {
  entry: './src/index.ts',
  output: {
    filename: "js/[name].js",
    path: resolve(__dirname, 'dist'),
  },

  module: {
    rules: [
      {
        test: /\.js$/i,

        use: [
          {
            loader: 'babel-loader', // options提取到babel.config.js
            /*            options: {
                          presets: [
                              "@babel/preset-env"
                              // ["@babel/preset-env", { //优先级高于.browserslistrc
                              //   targets: 'chrome 90'
                              // }]
                          ]
                        }*/
          }
        ]
      },
      {
        test: /\.tsx?$/i,
        exclude: /node_modules/,
        use: "babel-loader"
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HTMLWebpackPlugin({
      title: "Webpack App",
    }),
    new DefinePlugin({
      BASE_URL: "'./'"
    }),
  ],

  mode: 'development',
  devtool: 'source-map'
  /**
   * eval: 不生成source-map文件
   * cheap-source-map:不生成列报错，只生成行报错
   * cheap-module-source-map: (整体，没有单独的module)，类似于cheap-source-map，但是对源自loader的sourcemap处理会更
   */
}